package org.example.reflection;

import java.io.FileReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;

public class ReflectRead {
    public static void main(String[] args) throws Exception {
        // 获取键值对信息
        Properties properties = new Properties();
        FileReader reader = new FileReader("D:\\Project\\IDEAWorkSpace\\javabasic\\grammar\\src\\main\\java\\org\\example\\reflection\\class.txt");
        properties.load(reader);
        reader.close();

        // 获取数据
        String className = properties.getProperty("className");
        String methodName = properties.getProperty("methodName");

        // 反射
        Class<?> aClass = Class.forName(className);
        Constructor<?> constructor = aClass.getConstructor();
        Object o = constructor.newInstance();

        // 调用方法
        Method method = aClass.getMethod(methodName);
        method.invoke(o);
    }
}
